//
//  JMCPICell.m
//  NewiOSProject
//
//  Created by apple on 2023/9/16.
//  Copyright © 2023 范智渊. All rights reserved.
//

#import "JMCPICell.h"

@implementation JMCPICell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]){
        self.contentView.layoutMargins = UIEdgeInsetsMake(6, 15, 6, 15);
        self.contentView.cornerRadius = 20;
        self.backgroundColor = UIColor.clearColor;
        self.contentView.backgroundColor = UIColor.clearColor;
        [self setUI];
    }
    return self;
}
-(void)setUI{
    self.contV = [[UIView alloc]initWithFrame:(CGRectMake(0, 6, kAppW(), 133))];
    [self.contentView addSubview:self.contV];
    self.contV.cornerRadius = 20;
    self.contV.backgroundColor = WhiteColor();
    
    _iconImgV = [[UIImageView alloc]initWithFrame:(CGRectMake(24, 17, 36, 36))];
    [self.contV addSubview:self.iconImgV];

    
    _nameLab = [JMControl createLabelWithFrame:(CGRectMake(_iconImgV.right+12, _iconImgV.bottom+10, 100, FontH(13))) Font:fontWithWeight(15, UIFontWeightRegular) Text:@"Go Tunai" color:Text_COLOR_LEVEL1()];
    [self.contV addSubview:_nameLab];
    _nameLab.centerY = _iconImgV.centerY;
    
    _importLab = [JMControl createLabelWithFrame:(CGRectMake(_iconImgV.left, _iconImgV.bottom+8, kAppW()/2, FontH(14))) Font:Font(14) Text:@"Importe" color:Hex_Str_COLOR(@"#999999")];
    [self.contV addSubview:_importLab];
    
    _priceLab = [JMControl createLabelWithFrame:(CGRectMake(_importLab.left, _importLab.bottom+4, kAppW()/2, FontH(25))) Font:mediumFont(22) Text:@"$1,000" color:Text_COLOR_LEVEL1()];
    [self.contV addSubview:_priceLab];
    
    
    _timeLab = [JMControl createLabelWithFrame:(CGRectMake(113, _importLab.top, kAppW()/2, FontH(12))) Font:Font(14) Text:@"Plazo " color:Hex_Str_COLOR(@"#999999")];
    [self.contV addSubview:_timeLab];
    
    _termLab =[JMControl createLabelWithFrame:(CGRectMake(_iconImgV.right+125, _priceLab.top, kAppW()/2, _priceLab.height)) Font:mediumFont(22) Text:@"120 Días" color:Text_COLOR_LEVEL1()];
    [self.contV addSubview:_termLab];
    
   
    
    _btn = [JMControl createButtonWithFrame:(CGRectMake(kAppW()-154, 72, 120, 32)) Target:self Action:@selector(goLink) Title:@"Solicitar" titlColor:Hex_Str_COLOR(@"#ffffff") font:fontWithWeight(12, UIFontWeightRegular) tag:1 backgroundColor:mainGradientColor(CGSizeMake(120, 32))];
    _btn.cornerRadius = 16;
    [self.contV addSubview:_btn];
    _btn.centerY = self.contV.height/2;
    
}
-(void)goLink{
//    [JMCommonMethod pushWebviewWithUrl:self.model.externalLink andTitle:nil];
    JMGlobalHtmlVC *vc = JMGlobalHtmlVC.new;
    vc.url = self.model.externalLink;
    [JMCommonMethod uploadStatistics:@"CpiProduct" actionType:@"Click" parameters:@{@"id":self.model.id?:@""}];

    [self.superview.viewController.navigationController pushViewController:vc animated:YES];
}
-(void)setModel:(JMCPIModel *)model{
    _model = model;
    [_iconImgV sd_setImageWithURL:URLImageWithUrlStr(model.slogan) placeholderImage:nil];
    _priceLab.text = [NSString stringWithFormat:@"$%@",model.maxAmount.stringValue.moneyString];
    _nameLab.text = model.name;
    _termLab.text = [NSString stringWithFormat:@"%@ Días",model.term.stringValue];
//    _timeLab.text = model.remark;
    
}

@end
